package com.lingx.web.api.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.lingx.service.LingxService;
import com.lingx.service.ModelService;
import com.lingx.utils.HttpUtils;
import com.lingx.web.api.IApi;
@Component
public class Api9029 extends AbstractDevApi implements IApi{
	@Resource
	private LingxService lingxService;
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private ModelService modelService;
	@Override
	public int getApiCode() {
		return 9029;
	}
	@Override
	public String getApiName() {
		return "提交功能菜单";
	}
	@Override
	public Map<String, Object> api(Map<String, Object> params) {
		Map<String,Object> ret=IApi.getRetMap(1, "操作成功");
		String ecode=IApi.getParamString(params, "ecode", "");
		String url=this.lingxService.getConfigValue("lingx.update.submit.url", "none");
		Map<String,Object> req=new HashMap<>();

		req.put("apicode",8011 );
		req.put("funcJson",getFuncJson() );
		req.put("menuJson",getMenuJson() );
		req.put("secret",this.lingxService.getConfigValue("lingx.update.submit.secret", "none") );
		//System.out.println(JSON.toJSONString(req));
		HttpUtils.post(url, JSON.toJSONString(req));
		return ret;
	}
	public String getFuncJson() {
		List<Map<String,Object>> list=this.jdbcTemplate.queryForList("select * from tlingx_func");
		return JSON.toJSONString(list);
	}
	public String getMenuJson() {
		List<Map<String,Object>> list=this.jdbcTemplate.queryForList("select * from tlingx_menu");
		return JSON.toJSONString(list);
	}
}
